package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.RuralfileMapper;
import org.rcloud.io.model.Ruralfile;
import org.rcloud.io.service.RuralfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/21.
 */
@Service(value = "RuralfileService")
public class RuralfileServiceImpl implements RuralfileService {

    @Autowired
    private RuralfileMapper ruralfileMapper;


    @Override
    public ResultVo save(Ruralfile ruralfile) {

        if (ruralfile.equals("") || ruralfile == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                ruralfileMapper.insertSelective(ruralfile);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageVo<Ruralfile> findFileByNum(String id) {

        try {
            List<Ruralfile> list = ruralfileMapper.selectByNum(id);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateFile(int id) {

        try {
            ruralfileMapper.updateById(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo findFileById(int id) {

        try {
            Ruralfile ruralfile = ruralfileMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(ruralfile);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateFlagAll(String eid) {

        try {
            ruralfileMapper.updateFlagAll(eid);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateFlag(int id) {

        try {
            ruralfileMapper.updateFlag(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }
}
